package cn.edu.fzu.homemaking.domain.handler;

import cn.edu.fzu.homemaking.domain.enums.ChargeModeEnum;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @Author jiebin
 * @Date 2023/4/1
 */
public class ChargeModeEnumHandler extends BaseTypeHandler<ChargeModeEnum> {
    @Override
    public void setNonNullParameter(PreparedStatement preparedStatement, int i, ChargeModeEnum chargeModeEnum, JdbcType jdbcType) throws SQLException {
        preparedStatement.setInt(i,chargeModeEnum.getValue());
    }

    @Override
    public ChargeModeEnum getNullableResult(ResultSet resultSet, String s) throws SQLException {
        return ChargeModeEnum.parse(resultSet.getInt(s));
    }

    @Override
    public ChargeModeEnum getNullableResult(ResultSet resultSet, int i) throws SQLException {
        return ChargeModeEnum.parse(resultSet.getInt(i));
    }

    @Override
    public ChargeModeEnum getNullableResult(CallableStatement callableStatement, int i) throws SQLException {
        return ChargeModeEnum.parse(callableStatement.getInt(i));
    }
}
